<template>
  <div class="mt-20 ml-20 mr-20">
    <el-button class="mr-20" @click="handleLogin">登录</el-button>
    <el-input
      style="width: 200px"
      :key="passwordType"
      v-model="loginForm.password"
      :type="passwordType"
      placeholder="密码"
      name="password"
      tabindex="2"
    />
  </div>
</template>

<script>
// api
import { login } from '../../api/login'
import { setToken } from '@/utils/auth'
import md5 from 'js-md5'
export default {
  data() {
    return {
      loginForm: {
        password: ''
      },
      passwordType: 'password'
    }
  },

  methods: {
    async handleLogin() {
      const { data, code, msg } = await login({
        account: 'admin2',
        password: md5(this.loginForm.password)
      })
      // 请求成功
      if (code == 1) {
        setToken(data)
        this.$router.push('/home')
        return
      }

      this.$message.error(msg)
      console.log(data)
    }
  }
}
</script>

<style lang="less"></style>
